package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.Date;

import liumengbaio.lolzhangyoubao.Activity.InFo.MoreTreasureRecordInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * 往期记录界面 适配器
 * Created by lanouhn on 16/9/12.
 */
public class MoreTreasureRecordsAdapter extends BaseAdapter {
    private Context mContext;
    private MoreTreasureRecordInfo mtri;

    public MoreTreasureRecordsAdapter(Context mContext, MoreTreasureRecordInfo mtri) {
        this.mContext = mContext;
        this.mtri = mtri;
    }

    @Override
    public int getCount() {
        return mtri.getData().size();
    }

    @Override
    public Object getItem(int position) {
        return mtri.getData().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.item_more_treasure_record, null);
            holder.pic = (ImageView) convertView.findViewById(R.id.more_record_pic);
            holder.date = (TextView) convertView.findViewById(R.id.more_date);
            holder.time = (TextView) convertView.findViewById(R.id.more_time);
            holder.name = (TextView) convertView.findViewById(R.id.more_record_name);
            holder.amount = (TextView) convertView.findViewById(R.id.more_record_amount);
            holder.number = (TextView) convertView.findViewById(R.id.more_record_number);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Picasso.with(mContext).load(mtri.getData().get(position).getAvatar_url()).into(holder.pic);
        holder.date.setText(mtri.getData().get(position).getSequence());
        holder.name.setText(mtri.getData().get(position).getUser_name());
        holder.amount.setText("参与人次：" + mtri.getData().get(position).getRaid_num() + "");
        holder.number.setText("中奖号码：" + mtri.getData().get(position).getLucky_number() + "");
        Long data = mtri.getData().get(position).getReward_time() * 1000L;
        Date date = new Date(data);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        String update = format.format(date);
        holder.time.setText("揭晓时间：" + update);
        return convertView;
    }

    private class ViewHolder {
        private ImageView pic;
        private TextView name, amount, date, time, number;
    }
}
